- Java Unit Testing
- A Simple Unit Test
- Assert Methods
- Matchers
- Testing for Exceptions
- Stub, Mock and Proxy Testing
- Subclass Mock Objects
- Mock Testing isn't Always Enough
- IO Testing
- Servlet Unit Testing
- Unit Testing with Dependency Injection Containers
- Database Unit Testing - Rollback Transactions
- Database Unit Testing - CRUD Testing
- Database Unit Testing - Test Data Creation
- Running Unit Tests With Ant
- Running Unit Tests With Maven
- Running Unit Tests Inside IntelliJ IDEA
- Code Coverage
- Design for Testability
- Test First Development
Running Unit Tests With Maven
Jakob Jenkov |
If you are using the build tool Apache Maven, Maven can run your unit tests for you. In fact, you pretty much get that for free when using Maven. If you don't know Maven, it's a build tool like Ant, but more ambitious in my opinion.
I am not going to tell you everything about Maven here. It's a very extensive tool. I will just quickly show you how to run the unit tests with Maven, so you know that it is a possibility.
When you build a project using Maven, the build process passes through a set of phases. One of these
phases are called test. To execute the test phase, and all phases before it,
you use the following Maven command:
mvn test
That's pretty simple, isn't it? Of course, seing this command only makes sense if you know a little bit about how to set your code project up to use Maven. You can read more about that on the Maven site (see link above). Or, perhaps I will write about Maven in the future too.
Here is an example of the output from Maven:
Skipping the Tests
Maven always by default run your unit tests, if you run a mvn install which builds your project.
Sometimes, however, you want to build it without running the unit tests. You can do so, like this:
mvn install -Dmaven.test.skip=true
| Tweet | |
Jakob Jenkov | |









